package com.fwmagic.springcloud.service.impl;

import com.fwmagic.springcloud.service.IMessageProvider;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;

import javax.annotation.Resource;
import java.util.UUID;


/**
 * @description:
 * @author: fangwei
 * @date: 2022/4/11
 **/
@EnableBinding(Source.class) //可以理解为是一个消息的发送管道的定义
public class MessageProviderImpl implements IMessageProvider {

    //消息的发送管道
    @Resource
    private MessageChannel output;


    @Override
    public String send() {
        String serial = UUID.randomUUID().toString();
        System.out.println("*****发送消息:"+serial);
        Message<String> message = MessageBuilder.withPayload(serial).build();
        this.output.send(message);
        return serial;
    }
}